package com.example.xiaoshuo_yudu.mapper;

import com.example.xiaoshuo_yudu.entity.entity.ChapterTables;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 章节表元数据表 Mapper 接口
 * </p>
 *
 * @author xusen
 * @since 2025-07-27
 */
@Mapper
public interface ChapterTablesMapper extends BaseMapper<ChapterTables> {
    // 获取章节表名
    @Select("select table_name from chapter_tables where description=#{category}")
    String getChapterTableName(String category);
//    获取章节表
    @Select("select chapter_title,chapter_order from ${tableName} where book_id=#{bookId} order by chapter_order ")
    List<Map<String, Object>> getChapterListByBookId(String tableName, Integer bookId);
//    获取章节内容
    @Select("select chapter_title,chapter_content from ${tableName} where book_id=#{bookId} and chapter_order=#{chapterId}")
    Map<String, Object> getChapterDetail(String tableName, Integer bookId, Integer chapterId);
//    批量获取章节最后章节
    List<Map<String, Object>> batchGetChapterLastByBookIds(String tableName, List<Integer> bookIds);
    @Select("select chapter_title from ${tableName} where book_id=#{bookId}  and chapter_order=#{charterId}")
    String getChapterName(Long bookId, String tableName, Long charterId);
}
